import requests
import re



url = "https://image.baidu.com/search/acjson?tn=resultjson_com&ipn=rj&ct=201326592&is=&fp=result&queryWord=%E8%A1%A8%E6%83%85%E5%8C%85&cl=2&lm=-1&ie=utf-8&oe=utf-8&adpicid=&st=-1&z=&ic=&hd=&latest=&copyright=&word=%E8%A1%A8%E6%83%85%E5%8C%85&s=&se=&tab=&width=&height=&face=0&istype=2&qc=&nc=1&fr=&expermode=&force=&pn={}&rn=30&gsm=5a&1584535577367="
for i in range(3):
    pn=i*30
    img_url=url.format(pn)
    res = requests.get(img_url)
    data = res.text
    img_urls = re.findall(r'thumbURL":"(.*?)"', data)
    for index, img_url in enumerate(img_urls):
        print(index+i*30)
        res = requests.get(img_url)
        suffix = img_url.split(".")[-1]  # 拿文件后缀格式

        imgname = "emotion/img" + str(index) + str(i*30) + "." + suffix
        with open(imgname, "wb") as f:
            f.write(res.content)
print("ok")

